package inf3791.calendarsystem.shared;

import eu.mpower.mpoweractivityservice.soap.Event;
import java.util.Calendar;
import java.util.Date;

/**
 *
 * @author Jonas Weber
 */
public class Appointment {

    public enum AppointmentType {
        NONE (0),
        MEDICAL (100),
        FAMILY (200);

        private AppointmentType(long id) {
            this.id = id;
        }
        private final long id;
        
        long getId()
        {
            return id;
        }
                
    }
    private Date d;
    private String t;
    private String de;
    private AppointmentType type;

    public void setTime(Date d) {
        this.d = d;
    }

    public Date getTime() {
        return d;
    }

    public DaySpec getDaySpec() {
        Calendar c = Calendar.getInstance();
        c.setTime(d);

        return new DaySpec(c.get(Calendar.DATE), c.get(Calendar.MONTH), c.get(Calendar.YEAR));
    }

    public void setTitle(String title) {
        this.t = title;
    }

    public String getTitle() {
        return t;
    }

    public void setDescription(String description) {
        this.de = description;
    }

    public String getDescription() {
        return de;
    }

    public AppointmentType getAppointmentType()
    {
        return type;
    }

    public Appointment(Date d, String t, String de, AppointmentType type) {
        this.d = d;
        this.t = t;
        this.de = de;
        this.type = type;
    }

    public Appointment() {
    }

    public static Appointment fromEvent(Event e) {
        
        AppointmentType at;
        if (e.getEndDate() == AppointmentType.MEDICAL.getId())
        {
            at = AppointmentType.MEDICAL;
        } else if (e.getEndDate() == AppointmentType.FAMILY.getId())
        {
            at = AppointmentType.FAMILY;
        } else {
            at = AppointmentType.NONE;
        }
        
        return new Appointment(new Date(e.getStartDate()), e.getName(), e.getDescription(), at);
    }

    public Event toEvent() {
        Event evt = new Event();
        evt.setName(t);
        evt.setDescription(de);
        evt.setStartDate(d.getTime());
        evt.setEndDate(type.getId());
        return evt;
    }
}
